#include "ProductTestLed.h"

void ProductTest_Led_Set(int stat)
{
    switch(stat)
    {
    case LED_STATUS_ON:
    {
#if CMAKE_LED_ON_LOW_LEVEL
        Ext_SdkGpioWrite_Led(DEF_COM_LEVEL_LOW);
#else
        Ext_SdkGpioWrite_Led(DEF_COM_LEVEL_HIGHT);
#endif /* end of CMAKE_LED_ON_LOW_LEVEL */
    }
        break;

    case LED_STATUS_OFF:
    {
#if CMAKE_LED_ON_LOW_LEVEL
        Ext_SdkGpioWrite_Led(DEF_COM_LEVEL_HIGHT);
#else
        Ext_SdkGpioWrite_Led(DEF_COM_LEVEL_LOW);
#endif /* end of CMAKE_LED_ON_LOW_LEVEL */
    }
        break;

    case LED_STATUS_FAST:
        ProductTest_Led_Set(LED_STATUS_ON);
        usleep(250 * 1000);
        ProductTest_Led_Set(LED_STATUS_OFF);
        usleep(250 * 1000);
        ProductTest_Led_Set(LED_STATUS_ON);
        break;

    case LED_STATUS_SLOW:
        ProductTest_Led_Set(LED_STATUS_ON);
        usleep(1.5 * 1000 * 1000);
        ProductTest_Led_Set(LED_STATUS_OFF);
        usleep(1.5 * 1000 * 1000);
        ProductTest_Led_Set(LED_STATUS_ON);
        break;

    default:
        break;
    }
}

Com_pvoid ProductTest_Led_Thread(Com_pvoid arg)
{
    PRT_NORMAL("link led thread\n");

    while(DEF_COM_TRUE)
    {
        ProductTest_Led_Set(LED_STATUS_OFF);
        usleep(1000 * 1000);
    }

    return NULL;
}

void Ext_ProductTest_Led_Init(void)
{
    pthread_t id;

    pthread_create(&id, NULL, ProductTest_Led_Thread, NULL);
    pthread_detach(id);
}
